
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/taglib.jsp"%>
<%@ include file="/WEB-INF/jsp/include/script.jsp" %>  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>DataConverge</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link type="text/css" rel="stylesheet" href="css/xtree.css">
	<script src="js/xtreeForSearch.js"></script> 
    <script type="text/javascript">
      var xmlHttp;
      var url="";
      var delNode;     
      function createXMLHttpRequest() {
			if (xmlHttp == null) {
	    		if (window.ActiveXObject) {
	    			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	    		}
	    		else if (window.XMLHttpRequest) {
	        		xmlHttp = new XMLHttpRequest();                
	    		}
    		}
	  }
			  
      function change(){
      		var orgId=document.form0.org0.value;
      		var zhicheng=document.form0.zhicheng.value;
      		var name=document.form0.name.value;
      		//alert("org id is "+orgId+" zhicheng is "+zhicheng+" name is "+name);
            url="subject.htm?action=getResearchers&orgId="+orgId+"&zhicheng="+zhicheng+"&name="+escape(name);
     	    createXMLHttpRequest();
			xmlHttp.open("GET", url, true);
    		xmlHttp.onreadystatechange = callback;
    		xmlHttp.send(null);
      }
      function callback(){
      	if(xmlHttp.readyState==4){
    			if(xmlHttp.status==200){
    				clearResults();
    				parseMessage();
    			}
    		}
      }
      
      function parseMessage(){
      		var xmlDoc = xmlHttp.responseXML;
			var nodes = xmlDoc.getElementsByTagName('researcher');
			var res=document.getElementById("researchers");
			if(nodes!=null){
				var id="";
				var name="";
				var tr;
				for(var i=0;i<nodes.length;i++){
					//id=nodes[i].firstChild.firstChild.nodeValue;
					//name=nodes[i].lastChild.firstChild.nodeValue;
					id=nodes[i].getElementsByTagName("id")[0].firstChild.nodeValue;
					name=nodes[i].getElementsByTagName("name")[0].firstChild.nodeValue;
					if(i%9==0){
						tr=document.createElement("tr");
						res.appendChild(tr);	
					}
					addResN(id,name,tr);					
					//addRes(id,name);
				
				}
			}			
      }
      
      function addResN(id,name,parentNode){
      	var td=document.createElement("td");
        var input;
        var text;     
      	input=document.createElement("input");
		input.type="checkbox";
		input.value=id;
		input.name="researcherIds";
		input.setAttribute("nameValue",name);
		td.appendChild(input);
				
		text = document.createTextNode(name);
		td.appendChild(text); 
		parentNode.appendChild(td);
      }

      function clearResults(){
         	var res=document.getElementById("researchers");
         	while(res.childNodes.length > 0) {
				res.removeChild(res.childNodes[0]);
			}
      }
      
    	function showSubject(){
    		document.getElementById("subjectRelated").style.display="block";
    		document.getElementById("researcherRelated").style.display="none";
    	//	document.getElementById("orgRelated").style.display="none";
    	}
    	function showResearcher(){
    		document.getElementById("subjectRelated").style.display="none";
    		document.getElementById("researcherRelated").style.display="block";
    	//	document.getElementById("orgRelated").style.display="none";
    	}
   // 	function showOrg(){
   // 		document.getElementById("subjectRelated").style.display="none";
  //  		document.getElementById("researcherRelated").style.display="none";
   // 		document.getElementById("orgRelated").style.display="block";
    //	}
    	
    	function setValue(value){
    		document.getElementById("everyYear").value=value;
    		//alert("everyYear is "+document.getElementById("everyYear").value);
    		
    	}
    	
		function getFrameValues(){
			var parentNode=document.getElementById("tagIdPlace");
			var docu=document.frames("tagTreeFrame").document;
			var tagId;
			var input;
			for(i=0;i<docu.all.tags.length;i++){
					tagId=docu.all.tags[i].value;
					//alert(tagId);
					input=document.createElement("input");
					input.type="checkbox";
					input.name="tags";
					input.value=tagId;
					parentNode.appendChild(input);
					
					if(docu.all.tags[i].checked==true){
						parentNode.lastChild.checked=true;
					}					
			}
		}
		
		function clearSub(){
		   if(document.form0.all.contents.length>0){
			for(var i=0;i<document.form0.all.contents.length;i++){
    			if(document.form0.all.contents[i].checked==true){
    				document.form0.all.contents[i].checked=false;
    			}
    		}
		   }
		}
		
		function clearRes(){
			for(var i=0;i<document.form0.all.contentsRes.length;i++){
    			if(document.form0.all.contentsRes[i].checked==true){
    				document.form0.all.contentsRes[i].checked=false;
    			}
    		}
		}
		
    	function checkForm(){
    		var bool=false;  
    		var resBool=false; 		
    	//	var everyyear=document.getElementById("everyYear").value;
    	//	if(everyyear=="yes"){
    	//		if(document.form0.beginDate.value=="" || document.form0.endDate.value==""){
    	//			alert("请输入起始时间");
    	//			return false;
    	//		}
    	//	}
    		
    		for(var i=0;i<document.form0.all.contents.length;i++){
    			if(document.form0.all.contents[i].checked==true){
    				bool=true;
    	//			count++;
    			}
    		}
    		
    		for(var i=0;i<document.form0.all.contentsRes.length;i++){
    			if(document.form0.all.contentsRes[i].checked==true){
    				resBool=true;
    			}
    		}
    		
    		if(bool==false && resBool==false){
    			alert("请选择一项内容进行统计");
    			return false;
    		}else{
    			var fo=document.form0;
    			var exp = new RegExp("^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$");
    			if(fo.beginDate.value!="" && !exp.test(fo.beginDate.value)){
      				alert("请确认开始日期的格式!");
     				fo.beginDate.focus();
	  				return false;
	  			}
	  			if(fo.endDate.value!="" && !exp.test(fo.endDate.value)){
      				alert("请确认结束日期的格式!");
     				fo.endDate.focus();
	  				return false;
	  			}
	  			if(fo.state.value!=""){
	  				if(fo.endDate.value==""||fo.beginDate.value==""){
	  					alert("请填写开始日期和结束日期");
	  					return false;
	  				}
	  			}
    		} 
    		if(document.getElementById("researcherCondition").style.display=="block"){
    			//alert("researcher");
    			document.form0.condition.value="researcherCondition";
    			var trs=document.getElementById("researchers").childNodes;

				for(var i=0;i<trs.length;i++){
					var tds=trs[i].childNodes;
					for(var j=0;j<tds.length;j++){
						var checkb=tds[j].childNodes[0];
						if(checkb.checked==true){
							return true;
						}
					}
				}
    			/*for(i=0;i<document.all.researcherIds.length;i++){
    				alert(document.all.researcherIds[i].value);
					if(document.all.researcherIds[i].checked==true){
						return true;
					}					
				}*/
				alert("请至少选择一名科研人员！");
				return false;   			
    		}else{
    			//alert("subject");
    			document.form0.condition.value="subjectCondition";
    		}
    		
    		/*if(resBool==true) &&(document.getElementById("researcherCondition").style.display=="none"){
    			
    			alert("您在基于课题条件统计人员信息，请输入至少一个课题条件！");
    		}*/
    		return true;		
    	}
    	
    	function selectAll(){
    		var trs=document.getElementById("researchers").childNodes;
			for(var i=0;i<trs.length;i++){
				var tds=trs[i].childNodes;
				for(var j=0;j<tds.length;j++){
					tds[j].childNodes[0].checked=true;
				}
			}
    	}
    	function diselectAll(){
    		var trs=document.getElementById("researchers").childNodes;
			for(var i=0;i<trs.length;i++){
				var tds=trs[i].childNodes;
				for(var j=0;j<tds.length;j++){
					tds[j].childNodes[0].checked=false;
				}
			}
    	}
    	
    	function showDate(){
    		var state=document.form0.state.value;
    		if(state!=""){
    			document.getElementById("startDateTr").style.display="block";
    			document.getElementById("endDateTr").style.display="block";
    		}else{
    			document.getElementById("startDateTr").style.display="none";
    			document.getElementById("endDateTr").style.display="none";
    		}
    	}
    	
    	function showSubjectCondition(){
    	    document.getElementById("tree").style.display="block";
    		document.getElementById("subjectCondition").style.display="block";
    		document.getElementById("researcherCondition").style.display="none";
    	}
    	function showResearcherCondition(){
    	 	document.getElementById("tree").style.display="none";
    		document.getElementById("subjectCondition").style.display="none";
    		document.getElementById("researcherCondition").style.display="block";
    	}
    </script>
  </head>
  
  <body onload="change();">
<form name="form0" action="subjectAnalyze.htm" method="post" >
<IFRAME id="CalFrame"  
  style="DISPLAY: none; Z-INDEX: 100; WIDTH: 148px; POSITION: absolute;HEIGHT: 194px; left: 42px; top: 50px "
  marginWidth="0" marginHeight="0" 
  src="js/calendar/calendars.html" frameBorder="0"  
  noResize scrolling="no">
</IFRAME>
<br>
<table width="90%" height="65" border="1" align="center">
  <tr>
    <td height="29">
    	<font size="4"><strong>统计内容</strong></font>
    </td>
    <td height="29">
		<a href="#" onclick="showSubject();">统计课题相关</a><br>
		<a href="#" onclick="showResearcher();">统计参与人员</a><br>
    </td>
    <td>
      <p id="subjectRelated" style="display:block;">
      	  
   		    <c:forEach items="${topTags}" var="tag" varStatus="loopStep">
    		   <input name="contents" type="radio" value="${tag.id}" onclick="clearRes();">
    		   <c:out value="${tag.name}"/>&nbsp;&nbsp;
    		</c:forEach>         
	  </p>
	  <p id="researcherRelated" style="display:none;">
          <input name="contentsRes" type="radio" value="age" onclick="clearSub();">参与人员年龄 
		  <input name="contentsRes" type="radio" value="zhicheng" onclick="clearSub();">参与人员职称
		  <input name="contentsRes" type="radio" value="qualification" onclick="clearSub();">参与人员学历
		  <input name="contentsRes" type="radio" value="keysubject" onclick="clearSub();">重点学科领域
	  </p>
   </td>
  </tr>
</table>
<div align="center"><font size="4"><strong>统计条件</strong></font></div>
<table width="90%" height="70%" align="center" border="1">
<tr>

<td width="10%">
<a href="#" onclick="showSubjectCondition();">课题条件</a><br>
<a href="#" onclick="showResearcherCondition();">人员条件</a><br>
<input name="condition" type="hidden" value="subjectCondition"/>
</td>

<td width="90%" id="researcherCondition" style="display:none;">
  <table width="100%" border="1">
  			<tr>
				<td width="8%">所在单位</td>
				<td><select name="org0" onchange="change();">
						<option value=""></option>
    				<c:forEach items="${orgs}" var="org" varStatus="loopStep">
    					<option value="${org.id}"  <c:if test="${currentOrgId==org.id}">selected</c:if>><c:out value="${org.name}"/></option>;
    				</c:forEach>
    			    </select>
    			</td>
			</tr>
			<tr>
				<td>职称</td>
				<td><select name="zhicheng" onchange="change();">
						<option value=""></option>
						<option value="1">正高</option>
						<option value="2">副高</option>
						<option value="3">中级</option>
						<option value="4">初级</option>
						<option value="5">其它</option>
					</select>
				</td>
			</tr>
			<tr>
				<td>姓名</td>
				<td><input type="text" name="name" onkeyup="change();"></td>
			</tr>
			<tr>
  				<td>备选人<br><a href="#" onclick="selectAll();">全选</a>
  						 <br><a href="#" onclick="diselectAll();">全不选</a></td>
  				<td >
  					<TABLE>
  						<TBODY id="researchers">
  						</TBODY>
  					</TABLE>
				</td>  
			</tr>
			<tr>
  				<td>角色</td>
 				<td><select name="resRole">
 				       <option value="负责人">负责人</option>
 				       <option value="参与人员">参与人员</option>
 				    </select>
 			</td>
			</tr>
  </table>
</td>
<td width="30%" id="tree" style="display:block;">
<iframe width="260" height="100%" name="tagTreeFrame" frameborder="0" src="tagTree.htm?oper=search">
</iframe>
</td>

<td  width="60%" id="subjectCondition" style="display:block;">
<table width="100%" border="1">
 <tr style="display:none;">
  	<td id="tagIdPlace" colspan="2"></td>
 </tr>
<tr>
  	<td>统计单位</td>
    <td>
    	<select name="org">
    		<option value=""></option>
      		<c:forEach items="${orgs}" var="org" varStatus="loopStep">
    		  <option value="${org.id}">
    		    <c:out value="${org.name}"/>
    		  </option>
    		</c:forEach>
    	</select>
    	<input type="hidden" id="everyYear" name="everyYear" value="no"/>
    </td>
 </tr>
 <tr>
  	<td>单位角色</td>
    <td>
    	<select name="orgRole">
    		<option value=""></option>
      		<option value="牵头单位">牵头单位</option>
      		<option value="参与单位">参与单位</option>
    	</select>
    </td>
 </tr>
 <tr>
    <td>课题所属年份</td>
    <td><input name="belongYear" type="text" value="2006"/></td>
  </tr>
 <tr>
    <td>课题状态</td>
    <td><select name="state" onchange="showDate();">
  			<option value=""></option>
			<option value="0">申报中</option>
			<option value="5">未中标</option>
			<option value="1">中标</option>
			<option value="2">在研</option>
			<option value="3">申请结题</option>
			<option value="4">已结题</option>	
		</select>
	</td>
</tr>
<tr id="startDateTr" style="display:none;">
    <td>开始日期</td>
    <td><input type="text" name="beginDate"  onClick="ShowCalendar(this,this,null,0);" onkeydown="HideCalendar();" onblur="setFormatDate(this);">
    <font color="red">日期格式：yyyy-mm-dd</font> </td>
 </tr>
 <tr id="endDateTr" style="display:none;">
	<td>结束日期</td>
    <td ><input type="text" name="endDate"  onClick="ShowCalendar(this,this,null,0);" onkeydown="HideCalendar();" onblur="setFormatDate(this);"> 
  </td>
</tr>
</table>
</td>
</tr>
</table>
<div align="center"><input type="submit" value="统计" onClick="getFrameValues();setValue('no');return checkForm();">&nbsp;&nbsp;<input type="reset" value="取消"></div>
</form>
  </body>
</html>
